﻿using HMEngine.HMCameras;
using HMEngine.HMComponents;
using Microsoft.Xna.Framework;

namespace HMEngine.HMEffects {
    public sealed class HMShader : HMEffect {
        public HMShader(string asset) : base(asset) { }

        public override void SetParameters(IHMRenderable renderable) {
            Matrix world =
                HMCameraManager.ActiveCamera.World *
                Matrix.CreateScale(renderable.Scaling) *
                Matrix.CreateFromQuaternion(renderable.Rotation) *
                Matrix.CreateTranslation(renderable.Position);

            if (null != Effect.Parameters["World"]) {
                Effect.Parameters["World"].SetValue(world);
            }

            if (null != Effect.Parameters["View"]) {
                Effect.Parameters["View"].SetValue(HMCameraManager.ActiveCamera.View);
            }

            if (null != Effect.Parameters["Projection"]) {
                Effect.Parameters["Projection"].SetValue(HMCameraManager.ActiveCamera.Projection);
            }

            if (null != Effect.Parameters["EyePosition"]) {
                Effect.Parameters["EyePosition"].SetValue(HMCameraManager.ActiveCamera.Position);
            }

            if (null != Effect.Parameters["LightDirection"]) {
                Effect.Parameters["LightDirection"].SetValue(new Vector3(1, -1, -1));
            }

            if (null != Effect.Parameters["LightDiffuseColor"]) {
                Effect.Parameters["LightDiffuseColor"].SetValue(new Vector3(0.5f));
            }

            if (null != Effect.Parameters["LightSpecularColor"]) {
                Effect.Parameters["LightSpecularColor"].SetValue(new Vector3(0.5f));
            }
        }

        public override void UnloadContent() { }
    }
}